class BuildTypesController < ApplicationController
  def index
    list
    render :action => 'list'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  def list
    @title1 = 'Build types'
    @url1 = '/build_types/'
    @build_type_pages, @build_types = paginate :build_types, :per_page => 10
  end

  def show
    @title1 = 'Build types'
    @url1 = '/build_types/'
    @build_type = BuildType.find(params[:id])
    @title2 = @build_type.name;
    @url2 = "/build_types/show/#{@build_type.name}"
  end

  def new
    @title1 = 'Build types'
    @url1 = '/build_types/'
    @title2 = 'New'
    @url2 = '/build_types/new'
    @architectures = Architecture.find_all
    @build_type = BuildType.new
  end

  def create
    @build_type = BuildType.new(params[:build_type])
    if @build_type.save
      flash[:notice] = 'BuildType was successfully created.'
      redirect_to :action => 'list'
      
      # Make the build directory.
      FileUtils.mkdir("#{BuildTypesHelper::BUILD_DIRECTORY}#{@build_type.name}-#{@build_type.architecture.name}/");
      
      
    else
      render :action => 'new'
    end
  end

  def edit
    @title1 = 'Build types'
    @url1 = '/build_types/'
    @title2 = "Edit #{params[:id]}"
    @url2 = "/build_types/edit/#{params[:id]}"
    @architectures = Architecture.find_all
    @build_type = BuildType.find(params[:id])
  end

  def update
    @build_type = BuildType.find(params[:id])
    if @build_type.update_attributes(params[:build_type])
      flash[:notice] = 'BuildType was successfully updated.'
      redirect_to :action => 'show', :id => @build_type
    else
      render :action => 'edit'
    end
  end

  def destroy
    BuildType.find(params[:id]).destroy
    redirect_to :action => 'list'
  end
end
